package net.oschina.team.note.controller;

import net.oschina.team.note.bean.NotesTemplate;

import com.jfinal.core.Controller;

public class NotesTemplateController extends Controller {
	//修改用户的即时贴默认显示/隐藏
	public void updateStatus(){
		int user = getParaToInt("user");
		int status = getParaToInt("status", NotesTemplate.STATUS_SHOW);
		String sql = "SELECT * FROM notes_template WHERE user = ?";
		NotesTemplate notesTemplate = NotesTemplate.ME.findFirst(sql, user);
		NotesTemplate.ME.set("id", notesTemplate.get("id")).set("status", status).update();
		renderNull();
	}
	//重新设置默认属性
	public void resetStickySetting(){
		int id = getParaToInt("id");
		int user = getParaToInt("user");
		String content = getPara("content", NotesTemplate.DEFAULT_CONTENT);
		int width = getParaToInt("width", NotesTemplate.DEFAULT_WIDTH);
		int height = getParaToInt("height", NotesTemplate.DEFAULT_HEIGHT);
		int default_title_left = (width - NotesTemplate.DEFAULT_TITLE_IMG_WIDTH - 10*2)/2;
		int title_left = getParaToInt("title_left", default_title_left);
		String color = getPara("color", NotesTemplate.DEFAULT_COLOR);
		String style_t = getPara("style_t", NotesTemplate.DEFAULT_TITLE_STYLE);
		boolean result = NotesTemplate.ME.set("id", id).set("user", user).set("content", content).set("width", width)
			.set("height", height).set("title_left", title_left).set("color", color).set("style_t", style_t).update();
		if(result){
			renderText("success");
		}else{
			renderText("failure");
		}
	}
}